package cn.tradewin.pmp.pages.security;

import java.util.Date;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.pmp.persist.model.Contract;
import cn.tradewin.pmp.services.security.ContractService;

public class ContractAdd {

	@Inject
	Logger log;
	
	@Property
	private Contract contract;

	@Inject
	ContractService contractService;

	@Log
	@OnEvent(value=EventConstants.PREPARE)
	void onPrepare() {
		if (contract == null) {
			contract = new Contract();
			contract.setAssignDate(new Date());
			contract.setReleaseDate(new Date());
		}
	}
	
	void onSuccessFromAdd() {
		try {
			contractService.AddContract(contract);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
